#!/bin/sh
# This regression test is a part of SIPp.
# A failed RTP check exits with 253 (-3), and says so on stderr, with
# or without -trace_err.
. "`dirname "$0"`/../functions"; init

dir=`mktemp -d`
trap 'rm -rf "$dir"' EXIT

# A UAS without -rtp_echo: the pattern the UAC plays never comes back.
sippbg -sn uas -i 127.0.0.1 -p 25600 -m 2 \
    -min_rtp_port 25700 -max_rtp_port 25799

check() {
    sippfg -sf uac.xml -i 127.0.0.1 -p 25601 -m 1 -d 1000 \
        -min_rtp_port 25602 -max_rtp_port 25699 -audiotolerance 0.2 \
        127.0.0.1:25600 -timeout 10 -timeout_error "$@" \
        >/dev/null 2>"$dir/stderr"
    status=$?
    test $status -eq 253 || fail "exit code $status with '$*'"
    grep -q 'RTP check failed: pattern 1$' \
        "$dir/stderr" || fail "no RTP check message with '$*'"
}

check
check -trace_err -error_file "$dir/errors"
grep -q 'RTP check failed' "$dir/errors" ||
    fail "no RTP check message in the error file"
ok
